    //
//  Graph+Create.m
//  eyr
//
//  Created by Tor Gjøsæter on 4/24/12.
//  Copyright (c) 2012 University of Bergen. All rights reserved.
//

#import "Graph+Create.h"
#import "DataPointInTime+create.h"

@implementation Graph (Create)

+ (Graph *)createGraph:(NSDate *) date
inManagedObjectContext:(NSManagedObjectContext * ) context{
    Graph *g = nil;
    
    
    return g;   
}

+ (Graph *)createRandomGraph:(NSManagedObjectContext * ) context{
   
    int value = (arc4random() % 255) + 1;
    
    NSNumber *pressureValue = [[NSNumber alloc] initWithInt:value];
    
    Graph *graph;
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd-HH:mm"];
    
    
    
    NSDate *importDate = [NSDate date];  //Lager ein dato med denne tiden
    NSLog(@"Importdate: %@", importDate);
    
    DataPointInTime *dp1;
    DataPointInTime *dp2;    
    DataPointInTime *dp3;    
    
    
   
    dp1 = [DataPointInTime createDataPointInTime:[dateFormatter dateFromString:@"2012-01-01-09:00"] withPressure:pressureValue inManagedObjectContext:context];
    dp2 = [DataPointInTime createDataPointInTime:[dateFormatter dateFromString:@"2012-01-01-10:00"] withPressure:pressureValue inManagedObjectContext:context];
    dp3 = [DataPointInTime createDataPointInTime:[dateFormatter dateFromString:@"2012-01-01-11:00"] withPressure:pressureValue inManagedObjectContext:context];

    
    
    graph = [NSEntityDescription insertNewObjectForEntityForName:@"Graph" inManagedObjectContext:context];
    graph.importDato = importDate;
    [graph addDataPointsObject:dp1];
    [graph addDataPointsObject:dp2];
    [graph addDataPointsObject:dp3];
    

    return graph;
}

+ (NSString *) entireGraphDate:(Graph *)graph{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd-HH:mm"];
    
    //Optionally for time zone converstions
//    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]];
    
    NSString *stringFromDate = [formatter stringFromDate:graph.importDato];
    return stringFromDate;
}



@end
